<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%><%-- ${fn:length(list)} --%>
<script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript">
	$(document).ready(function(){
		$("#operation").hide();
		$("#defect").hide();
		$("#showMaterial").click(function(){
			$("#materiales").show();
			$("#defect").hide();
			$("#operation").hide();
		});
		$("#showOperation").click(function(){
			$("#materiales").hide();
			$("#defect").hide();
			$("#operation").show();
		});
		$("#showDefect").click(function(){
			$("#materiales").hide();
			$("#operation").hide();
			$("#defect").show();
		});
		$("#insertMeterialBtn").click(function(){
			if($("#item_id_ice").val()==""){
				alert("Please insert Quantity");
				$("#item_id_ice").fucus();
				return false;
			}
			if($("#item_id_pc").val()==""){
				alert("Please insert Quantity");
				$("#item_id_pc").fucus();
				return false;
			}
			if($("#item_id_rb").val()==""){
				alert("Please insert Quantity");
				$("#item_id_rb").fucus();
				return false;
			}
			if($("#item_id_tp").val()==""){
				alert("Please insert Quantity");
				$("#item_id_tp").fucus();
				return false;
			}
			// 재고 등록후
			$.ajax({
				type:"post",
				url:"wip.do",
				data:$("#insertMaterialForm").serialize(),
				dataType:"json",
				success:function(data){
		
					var update= "";
					 $.each(data.list,function(index,value){
						 update+="<tr><td>"+value.ROWNUM +"</td>";
					 	 update+=	"<td>"+value.ITEM_ID +"</td>";
						 update+="<td>"+value.ITEM_DESC+"</td>";
						 update+="<td>"+value.ITEM_AMOUNT+"</td>";
						 update+="<td>"+value.ITEM_TYPE +"</td></tr>";
					}); 
					var c= confirm("         재고등록완료.\nWork Order 등록페이지로 이동 하시겠습니까?");
					if(c){
						location.href="workorder.do?command=main";
					}else{
						location.href="wip.do?command=main";
					}
				},
				error:function(data){
					alert("실패");
				}
			});//ajax
		});
		$("#insertOperationBtn").click(function(){
			$.ajax({
				url:"wip.do?command=addOperation",
				data:$("#operationForm").serialize(),
				dataType:"json",
				success : function(js){
					var tbody = "";
					$.each(js.list,function(index, value){
						tbody+="<tr><td>"+value.ROWNUM+"</td><td>"+value.OPERATION_ID+"</td><td>"+value.OPERATION_DESC+"</td></tr>";
					});
					$("#operationListBody").html(tbody);				
					$(":input:text").val("");
				},
				error : function(){
					alert("error..");
				}
			}); // operationInsert Btn Click Ajax
		}); // operation Btn Click
		
		$("#insertDefectBtn").click(function(){
			$.ajax({
				url:"wip.do?command=addDefect",
				data:$("#defectForm").serialize(),
				dataType:"json",
				success : function(js){
					alert("success");
					var tbody = "";
					$.each(js.list,function(index, value){
						tbody+="<tr><td>"+value.ROWNUM+"</td><td>"+value.DEFECT_ID+"</td><td>"+value.DEFECT_DESC+"</td></tr>";
					});
					$("#defectListBody").html(tbody);				
					$(":input:text").val("");
				},
				error : function(){
					alert("error..");
				}
			}); // defect Btn Click Ajax
		}); // defect Btn Click
	});
</script>
<p class="title">Work In Progress</p>
<input type="button" id="showMaterial" value="Material 관리">
<input type="button" id="showOperation" value="Operation 관리">
<input type="button" id="showDefect" value="Defect 관리">
<div id="materiales">
<hr>
<p class="title">Material Insert<p>
<form id="insertMaterialForm">
<input type="hidden" name="command" value="updateMaterial">
<table  border="1" cellspacing='0' width="800px" >
	<tr>
		<td width="20%" >Item</td>	<td>ICE</td>	<td width="20%" >Plastic Container</td>		<td>RedBean</td>	<td>Topping</td>
		<td rowspan="2" width="12%"><input type="button" id="insertMeterialBtn" value="자재주문" style="height: 40px; width: 66px"></td>
	</tr>
	<tr>
		<td width="20%">Quantity</td>	
		<c:if test="${param.item_id_ice !=null}">
		<td><input type="text" id="item_id_ice" name="item_id_ice" readonly="readonly" value="${param.item_id_ice }"></td>	
		</c:if>
		<c:if test="${param.item_id_ice ==null}">
		<td><input type="text" id="item_id_ice" name="item_id_ice"></td>
		</c:if>
		<c:if test="${param.item_id_pc !=null}">
		<td><input type="text" id="item_id_pc" name="item_id_pc" readonly="readonly" value="${param.item_id_pc }"></td>	
		</c:if>
		<c:if test="${param.item_id_pc ==null}">
		<td><input type="text" id="item_id_pc" name="item_id_pc"></td>
		</c:if>
		<c:if test="${param.item_id_rb !=null}">
		<td><input type="text" id="item_id_rb" name="item_id_rb" readonly="readonly" value="${param.item_id_rb }"></td>	
		</c:if>
		<c:if test="${param.item_id_rb ==null}">
		<td><input type="text" id="item_id_rb" name="item_id_rb"></td>
		</c:if>
		<c:if test="${param.item_id_tp !=null}">
		<td><input type="text" id="item_id_tp" name="item_id_tp" readonly="readonly" value="${param.item_id_tp }"></td>	
		</c:if>
		<c:if test="${param.item_id_tp ==null}">
		<td><input type="text" id="item_id_tp" name="item_id_tp"></td>
		</c:if>
	</tr>
</table>
</form>

<br><hr>
<p class="title">Material List</p>
<table border="1" cellspacing='0' width="800px">
	<tr>
		<td width="11%">NO</td>
		<td width="11%">ID</td>
		<td width="44%">DESC</td>
		<td>AMOUNT</td>
		<td width="12%">TYPE</td>
	</tr>
	<tbody id="materialListBody">
	<c:forEach items="${requestScope.map.material }" var="list">
	<tr>
		<td>${list.ROWNUM }</td>
		<td>${list.ITEM_ID }</td>
		<td>${list.ITEM_DESC}</td>
		<td>${list.ITEM_AMOUNT}</td>
		<td>${list.ITEM_TYPE }</td>
	</tr>
	</c:forEach>
	</tbody>
</table>
</div>

<div id="operation">
<hr>
<p class="title">Operation List</p>
<table border="1" cellspacing='0' width="800px">
	<tr>
		<td width="22%">NO</td>
		<td width="22%">ID</td>
		<td>DESC</td>
	</tr>
	<tbody id="operationListBody">
	<c:forEach items="${requestScope.map.operation}" var="list">
	<tr>
		<td>${list.ROWNUM }</td>
		<td>${list.OPERATION_ID }</td>
		<td>${list.OPERATION_DESC}</td>
	</tr>
	</c:forEach>
	</tbody>
</table>
</div>

<div id="defect">
<hr>
<p class="title">Defect List</p>
<table border="1" cellspacing='0' width="800px">
	<tr>
		<td width="22%">NO</td>
		<td width="22%">ID</td>
		<td>DESC</td>
	</tr>
	<tbody id="defectListBody">
	<c:forEach items="${requestScope.map.defect }" var="list">
	<tr>
		<td>${list.ROWNUM }</td>
		<td>${list.DEFECT_ID }</td>
		<td>${list.DEFECT_DESC}</td>
	</tr>
	</c:forEach>
	</tbody>
</table>
</div>


